package com.lcc.dingtalk.robot.service.account.impl;

import cn.hutool.json.JSONUtil;
import com.lcc.dingtalk.robot.mapper.AccountBankDetailConfigMapper;
import com.lcc.dingtalk.robot.pojo.account.AccountBankDetailConfigPO;
import com.lcc.dingtalk.robot.service.account.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author lincc
 * @version 1.0 2020/7/23
 */
@Slf4j
@Service
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountBankDetailConfigMapper accountBankDetailConfigMapper;

    private static List<String> TRANS_TYPE_LIST = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "9", "C");

    @Override
    public void updateAccountBankDetailConfig() {
        List<AccountBankDetailConfigPO> list = accountBankDetailConfigMapper.selectList(null);
        System.out.println(list.size());
        list.stream().filter(config ->
                        config.getSuccThreeElementTransType() == null
//                    && "lcctest".contains(config.getUrid())
        ).forEach(config -> {
            System.out.println("原始数据：" + JSONUtil.toJsonStr(config));
            System.out.println(TRANS_TYPE_LIST);
            String[] fourElementMatchTransType = config.getFourElementMatchTransType()==null?new String[]{}:config.getFourElementMatchTransType().split(",");
            List<String> list1 = new ArrayList<>(TRANS_TYPE_LIST);
            List<String> needRemoveList = new ArrayList<>(Arrays.asList(fourElementMatchTransType));
            list1.removeAll(needRemoveList);
            System.out.println(list1);
            config.setSuccThreeElementTransType(String.join(",", list1));
            config.setFailThreeElementTransType(String.join(",", list1));
            accountBankDetailConfigMapper.updateById(config);
        });
    }
}
